#ifndef _RENDERER_H_
#define _RENDERER_H_

#include <glm.hpp>
#include <memory>
#include <GameObject/Object.h>
#include <ScriptEngine/ScriptType.h>
#include <optional>
#include <Renderer/Texture.h>

namespace Engine2D
{
    struct Vertex
    {
        glm::vec4 pos;          // 方便矩阵变换，2D只有前两个有作用
        glm::vec4 color;
    };

    enum RendererType
    {
        Renderer_SDL
    };
    
    class Renderer 
    {
    public:
        static std::shared_ptr<Renderer> Instance();
        virtual void SetWindow(void * wind) = 0;
        virtual void Clear(int r, int g, int b, int a = 255) = 0;
        virtual void Render() = 0;
        virtual void* GetRenderer() = 0;
        virtual void DrawPolygon(std::vector<Vertex> & vertex, std::vector<int> & indices = std::vector<int>()) = 0;
        virtual void DrawTexture(std::shared_ptr<Texture> texture, std::optional<SLua_Rect> & src, std::optional<SLua_Rect> & dst) = 0;
        void SetMainCamera(std::shared_ptr<IObject> camera) { m_camera = camera; }
        std::shared_ptr<IObject> MainCamera() { return m_camera.lock(); }

    protected:
        Renderer() = default;
        virtual ~Renderer() = default;

        std::weak_ptr<IObject> m_camera;
        inline static std::shared_ptr<Renderer> s_renderer;
    };

    // std::shared_ptr<Renderer> CreateRenderer(RendererType type);

} // namespace Engine2D


#endif